format datetime python pandas

39

formatted_df = df["Date"].dt.strftime("%m/%d/%y")
df['DOB']=pd.to_datetime(df['DOB'].astype(str), format='%m/%d/%Y')
df.style.format({"DOB": lambda t: t.strftime("%m/%d/%Y")})
df.style.format({"DOB": lambda t: t.strftime("%d-%m-%Y")})
import pandas as pd

df = pd.DataFrame({'DOB': {0: '26/1/2016 ', 1: '26/1/2016 '})
print(df.dtypes)

df['DOB1'] = df['DOB'].dt.strftime('%m/%d/%Y')
print(df.dtypes)

df['DOB1'] = pd.to_datetime(df['DOB1'])
print(df.dtypes)

Comments

Submit
0 Comments